const mongoose = require('mongoose')
const bcypt = require('../utils/encrypt')

// 用户表
const userSchema = new mongoose.Schema({
    user: { type: String, required: true, unique: true },
    pwd: {
        type: String,
        required: true,
        select: false,
        // 使用mongodb提供的的set操作方法直接加密密码
        set: value => bcypt(value),
    },
    email: String,
    phone: String,
    isaAdmin: { type: Boolean, default: true, select: false }, // 管理权限
    createtime: {
        type: String,
        default: new Date().toLocaleString('zh-cn', { hour12: false }),
    }, //创建时间
})

module.exports = User = mongoose.model('user', userSchema)
